package com.one.servlet;

import com.one.pojo.Books;
import com.one.service.bookService;
import com.one.service.impl.bookServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

/**
 * @author LJ
 * @create 2022-04-24-22:30
 */
@WebServlet("/index")
public class indexServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        HttpSession session = req.getSession();
        String haha = req.getParameter("haha");
        if (haha!=null){
            if (Integer.parseInt(haha)==1){
                session.invalidate();
            }
        }
        bookService bookService = new bookServiceImpl();
        List<Books> list = bookService.allBooks();
        req.setAttribute("list", list);
        req.getRequestDispatcher("main.jsp").forward(req, resp);
    }


}
